// pages/miaosha/miaosha.js
var app=getApp();
var util=require("../../utils/util.js");
var baseImgUrl=util.baseImgUrl;
var goodsPic1 = baseImgUrl+"erji.png";
var goodsPic2 = baseImgUrl+"huodong.png";
var isnonePic = "/pages/images/miaosha_none.png"
Page({

  /**
   * 页面的初始数据
   */
  data: {
      isnone:false,//是否为空，true--空 false--非空
      isnonePic : "/pages/images/miaosha_none.png",
      days:"05",
      hours:"00",
      minutes:"00",
      seconds:"05",
      timerPic:"/pages/images/timer.png",
      goodsPic1:baseImgUrl+"erji.png",
      goodsPic2:baseImgUrl+"huodong.png",
      goodslist:[{
        id:0,
        goodspic:goodsPic1,
        goodsname:"家用迷你电烤箱 红外线速热 控温简单 烘焙必备",
        price:99.99,
        priceY:399,
        progress:33,
        status: true,//在售 false--已抢完
      },
        {
          id: 10,
          goodspic: goodsPic1,
          goodsname: "家用迷你电烤箱 红外线速热 控温简单 烘焙必备",
          price: 99.99,
          priceY: 399,
          progress: 33,
          status:true,//在售 false--已抢完
        },
        {
          id: 1,
          goodspic: goodsPic2,
          goodsname: "入耳式耳机 低音高音质低音音响,入耳式耳机 低音高音质低音音响,入耳式耳机 低音高音质低音音响 ",
          price: 19.99,
          priceY: 99,
          progress: 33,
          status: true,//在售 false--已抢完
        }, 
        {
          id: 2,
          goodspic: goodsPic2,
          goodsname: "入耳式耳机 低音高音质低音音响 ",
          price: 19.99,
          priceY: 99,
          progress: 33,
          status:false,//在售 false--已抢完
        }]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    // var timers=this.data.hours*3600+this.data.minutes*60+this.data.seconds*1;
    countdown(that);
   
   

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
     
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    util.loading();
    //请求数据

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  
 

})

function countdown(that) {
  var day=that.data.days;
  var hour=that.data.hours;
  var minute=that.data.minutes;
  var second = that.data.seconds;
  var times=day*24*3600+hour*3600+minute*60+second*1;
  if (times <= 0) {
    clearInterval(timer);
  
    return;
  }
  var timer = setInterval(function () {
    if (times > 0) {
      day=Math.floor(times/(60*60*24));
      hour = Math.floor((times -day*24*3600)/ (60 * 60));
      minute = Math.floor((times-day*24*3600-hour* 60*60)/ 60);
      second = Math.floor(times) -(day*24*60*60)- (hour * 60 * 60) - (minute * 60);
    }
    if(day <= 9) day = "0"+day;
    if (hour <= 9) hour = '0' + hour;
    if (minute <= 9) minute = '0' + minute;
    if (second <= 9) second = '0' + second;
    times--;
    that.setData({
      days:day,
      hours: hour,
      minutes: minute,
      seconds: second
      
    });
    // countdown(that);
  }, 1000)
}


